<template>
  <div class="form2">
    <Header_></Header_>
    <div class="form2_content">
      <el-form :model="form2Data" :rules="rules" ref="form2" label-width="80px" class="demo-ruleForm" :status-icon="statusIcon" label-position="top">
        <!--        公司名称-->
        <el-form-item label="公司名称" prop="company_name">
          <el-input v-model="form2Data.company_name"></el-input>
        </el-form-item>
        <!--        所属行业-->
        <el-form-item label="所属行业" prop="industry" required>
          <el-input v-model="form2Data.industry"></el-input>
        </el-form-item>
        <!--        在职时间-->
        <Date_ :form2Data="form2Data"></Date_>
        <!--        职位名称-->
        <el-form-item label="职位名称" prop="position_name" required>
          <el-input v-model="form2Data.position_name"></el-input>
        </el-form-item>
        <!--        工作描述-->
        <el-form-item label="工作描述" prop="desc">
          <el-input type="textarea" v-model="form2Data.desc" resize="vertical"></el-input>
        </el-form-item>
        <el-form-item class="btn-container">
          <el-button @click="resetForm('form2')">重置</el-button>
          <el-button type="primary" @click="submitForm('form2')">下一步</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import Header_ from '../form1/component/Header_'
import Date_ from './component/Date_'

export default {
  name: 'index',
  components: {Date_, Header_},
  data() {
    return {
      statusIcon: true,
      // form2数据
      form2Data: {
        company_name: '',
        industry: '',
        start_date: '',
        end_date: '',
        position_name: '',
        desc: ''
      },
      // 验证规则
      rules: {
        company_name: [
          {required: true, message: '请输入公司名称', trigger: 'blur'}
        ],
        industry: [
          {required: true, message: '请输入您上家公司所属行业', trigger: 'blur'}
        ],
        start_date: [
          {required: true, message: '请输入您的在职时间', trigger: 'blur'}
        ],
        end_date: [
          {required: true, message: '请输入您的在职时间', trigger: 'blur'}
        ],
        position_name: [
          {required: true, message: '请输入您的职位名称', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
          console.log(this.form2Data)
          this.$router.push('/form3')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
.form2 {

  box-sizing: border-box;
  margin: 0 auto;
  width: 500px;
  overflow: auto;
  background-color: #ffffff;
  border: 1px solid #cccccc;
  border-radius: 12px;
  margin-top: 20px;

  .form2_content {
    padding: 0 20px;
  }

  .btn-container {
    display: flex;
    justify-content: flex-end;
  }
}
</style>
